package com.wxlsoft.excel.convert.listeners;

import javax.swing.JProgressBar;

import com.alibaba.excel.context.AnalysisContext;
import com.wxlsoft.excel.convert.handlers.ServicePackageConverter;
import com.wxlsoft.excel.convert.handlers.ServicePackageParser;
import com.wxlsoft.excel.convert.model.BasePackageRecord;
import com.wxlsoft.excel.convert.model.ServiceBody;
import com.wxlsoft.excel.convert.model.ServicePackage;
import com.wxlsoft.excel.convert.model.SheetDataConvertCollector;

import lombok.NonNull;

/**
 * 公共报文头
 * @author wangxiaoliang
 */
public class CommonPackageListener extends AbstractPackageListener {

	private final ServicePackage common = new ServicePackage();
	
	public CommonPackageListener(String sheetName, JProgressBar progress,
			@NonNull final SheetDataConvertCollector collector) {
		super(sheetName, progress, collector);
	}
	
	@Override
	protected void serviceBodyInput(BasePackageRecord data, AnalysisContext context) {
		ServiceBody bodyInput = ServicePackageParser.toServiceBody(data);
		common.addServiceBodyInput(bodyInput);
	}

	@Override
	protected void serviceBodyOutput(BasePackageRecord data, AnalysisContext context) {
		ServiceBody bodyOutput = ServicePackageParser.toServiceBody(data);
		common.addServiceBodyOutput(bodyOutput);
	}

	@Override
	protected void doAfter(AnalysisContext context) {
		ServicePackageConverter.convertCommonPackage(common);
		collector.setHeadPackage(common);
	}
	
}
